package net.golfklubi.sive;

import org.apache.wicket.Page;
import org.apache.wicket.RestartResponseAtInterceptPageException;
import org.apache.wicket.authorization.strategies.page.AbstractPageAuthorizationStrategy;

public class SiveStrategy extends AbstractPageAuthorizationStrategy {

    @Override
    protected <T extends Page> boolean isPageAuthorized(final Class<T> pageClass) {
        final SiveWebSession siveSession = SiveWebSession.getSiveSession();
        final boolean signedIn = siveSession.isSignedIn();
        if (Securable.class.isAssignableFrom(pageClass) && !signedIn) {
            throw new RestartResponseAtInterceptPageException(SiveLoginPage.class);
        }
        return true;
    }
}
